package com.hulytu.android.mvvm.viewmodel;

import androidx.collection.ArraySet;
import androidx.lifecycle.ViewModel;

import com.hulytu.android.mvvm.viewmodel.usecase.UseCase;

import java.util.Iterator;
import java.util.Set;

public abstract class BaseViewModel extends ViewModel {

    private final Set<UseCase> mUseCases = new ArraySet<>();


    protected void addUseCase(UseCase useCase) {
        mUseCases.add(useCase);
    }


    @Override
    protected void onCleared() {
        super.onCleared();
        Iterator<UseCase> iterator = mUseCases.iterator();
        while (iterator.hasNext()) {
            iterator.next().onCleared();
            iterator.remove();
        }
    }
}
